<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <!--引入js-->
    <script type="text/javascript" src="/js/jquery.js"></script></head>
    <script type="text/javascript" src="/js/index.js"></script></head>
<body>
    <h1 style="text-align: center">首页</h1>
    <table border="2" style="margin: auto">
        <tr>
            <td>用户名：</td>
            <td>
                <input id="uname" name="username" type="text" placeholder="请输入用户名称">
            </td>
        </tr>
        <tr >
            <td colspan="2" align="center">
                <input id="btn" type="button" value="到聊天界面" onclick="login()">
            </td>
        </tr>
    </table>
</body>
<script>
    function login() {
        var data = {};
        data['username'] = $('#uname').val();
        $.ajaxSetup({contentType: "application/json; charset=utf-8"})
        $.post("login", JSON.stringify(data), function (res) {
            if (res.flag){
                location.href = 'toChatroom';
            }else {
                alert(JSON.stringify(res));
            }
        }, 'json');
    }
</script>
</html>
